﻿using System;
using System.Collections.Generic;
using System.Linq;
using Interfaces.CommonData;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockInfoLoader;
using StockInfoLoader.Utils;

namespace TST_ALL
{
    [TestClass]
    public class TST_Loaders
    {
        private static DateInterval dt_SingleStock;

        [ClassInitialize]
        public static void InitFields(TestContext ctx)
        {
            dt_SingleStock = new DateInterval();
            dt_SingleStock.DateTo = DateTime.Today;
            dt_SingleStock.DateFrom = dt_SingleStock.DateTo.AddYears(-5);
        }

        [TestMethod]
        public void TST_SingleStock()
        {
            var ldr = new SingleStockPriceLoader();
            var lstPrices = ldr.LoadAdjustedStockPrices("AAPL", 1, dt_SingleStock);
            Assert.AreNotEqual(lstPrices.Count, 0);
        }

        [TestMethod]
        public void TST_ExtractPrices()
        {
            string url = "http://real-chart.finance.yahoo.com/table.csv?s=AAPL&a=1&b=1&c=2010&d=1&e=1&f=2015&g=d&ignore=.csv";

            string dataDump = string.Empty;
            ExtractorHelper.ExtractResults res = ExtractorHelper.ExtractHTTP(url, out dataDump);

            Assert.AreEqual(res, ExtractorHelper.ExtractResults.Success);
            Assert.AreNotEqual(dataDump.Count(),0);
        }

        [TestMethod]
        public void TST_IndexConstituents()
        {
            IndexCompositionLoader ix = new IndexCompositionLoader();
            List<Stock> lstStocks = ix.LoadIndexComposition(IndexName.SAndP100);

            Assert.AreEqual(lstStocks.Count, 100);
        }
    }
}
